﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
      <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no" />
    <title></title>
    <link href="../Frozenui1.3/css/frozen.css" rel="stylesheet" />
    <script src="../JS/zepto.min.js"></script>
    <script src="../Frozenui1.3/js/frozen.js"></script>
    <script src="../JS/MobileCom.js?r=20150825"></script>
    <script >
        document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {
            //隐藏右上角按钮
            WeixinJSBridge.call('hideOptionMenu');
        });
        var url = "";
        $(function () {

            //var appid = "wxf285796b249c0cf6";
            var appid = "";//"wx102a8aac04b33c39";aeac70cc-c359-45f2-90ac-78cb7abe5816
            
            var funcode = MobileCom.getQueryString("funcode");
            var code = MobileCom.getQueryString("code");
            var state = MobileCom.getQueryString("state");
            

            if (MobileCom.getCookie("szhlcode")) {  //缓存的用户名，直接跳到对应的地址
                $.getJSON("/API/WXAPI.ashx?action=isexist&r=" + Math.random(), {}, function (r) {
                    if (r.ErrorMsg == "") {
                        $.getJSON("/API/SZHLAPI.ashx?action=GETQYINFO&r=" + Math.random(), {}, function (r) {
                            if (r.ErrorMsg == "") {
                                appid = r.Result.corpId;
                                url = r.Result.WXUrl;
                                var str = r.Result.WXUrl;
                                if (str.substr(str.length - 1, 1) == "/") {
                                    url = str;
                                } else {
                                    url = str + "/";
                                }
                                window.location.replace(getRURL(funcode));
                            }
                        })
                    }
                    else {
                        MobileCom.delCookie("szhlcode");
                        window.location.replace(window.location.href);
                    }
                })
            }
            else {   //获取授权

                $.getJSON("/API/SZHLAPI.ashx?action=GETQYINFO&r=" + Math.random(), {}, function (r) {
                    if (r.ErrorMsg == "") {
                        appid = r.Result.corpId;
                        url = r.Result.WXUrl;
                        var str = r.Result.WXUrl;
                        if (str.substring(str.length - 1, 1) == "/") {
                            url = str;
                        } else {
                            url = str + "/";
                        }


                        if (code) {   //授权回来，抓取用户名
                            var el = $.loading({
                                content: '加载中...',
                            });

                            $.getJSON("/API/WXAPI.ashx?action=GetUserCodeByCode&r=" + Math.random(), { "code": code }, function (r) {
                                el.loading("hide");
                                if (r.ErrorMsg == "") {
                                    MobileCom.setCookie("szhlcode", r.Result, 7);
                                    window.location.replace(getRURL(state));
                                } else {
                                    alert(r.ErrorMsg);
                                }

                            })


                        } else { //微信企业号接口获取授权

                            var wx_r_url = encodeURIComponent(url + "MobileView/UI/UI_COMMON.html");

                            var wxurl = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + appid + "&redirect_uri=" + wx_r_url + "&response_type=code&scope=snsapi_base&state=" + funcode + "#wechat_redirect";

                            window.location.replace(wxurl);
                        }
                    }
                })
            }

        })



        function getRURL(funcode) {
            
            var id = "";
            if (funcode.indexOf("_") > 0) {
                id = funcode.split('_')[1];
                funcode = funcode.split('_')[0];
            }
            var rr_url = url + "MobileView/UI/";
            switch (funcode) {
                case "qygg": //企业公告
                    {
                        rr_url += "UI_QYGG_LIST.html?r=" + Math.random();
                    }
                    break;
                case "qygga": //企业公告查看
                    {
                        rr_url += "UI_QYGG_INFO.html?id=" + id + "&r=" + Math.random();
                    }
                    break;
                case "gzrba":  //工作日报添加
                    {
                        rr_url += "UI_GZRB_INPUT.html?r=" + Math.random();
                    }
                    break;
                case "gzrbb":  //工作日报列表
                    {
                        rr_url += "UI_GZRB_LIST.html?r=" + Math.random();
                    }
                    break;
                case "gzrbc": //工作日报查看
                    {
                        rr_url += "UI_GZRB_INFO.html?id=" + id + "&r=" + Math.random();
                    }
                    break;
                case "khgla":  //客户管理添加
                    {
                        rr_url += "UI_KHGL_INPUT.html?r=" + Math.random();
                    }
                    break;
                case "khglb":  //客户管理列表
                    {
                        rr_url += "UI_KHGL_LIST.html?r=" + Math.random();
                    }
                    break;
                case "hdbma":  //活动报名添加
                    {
                        rr_url += "UI_HDBM_INPUT.html?r=" + Math.random();
                    }
                    break;
                case "hdbmb":  //活动报名列表
                    {
                        rr_url += "UI_HDBM_LIST.html?r=" + Math.random();
                    }
                    break;
                case "hdbmc": //活动报名查看
                    {
                        rr_url += "UI_HDBM_INFO.html?id=" + id + "&r=" + Math.random();
                    }
                    break;
                case "qjcca":  //请假出差添加
                    {
                        rr_url += "UI_QJCC_INPUT.html?r=" + Math.random();
                    }
                    break;
                case "qjccb":  //请假出差列表
                    {
                        rr_url += "UI_QJCC_LIST.html?r=" + Math.random();
                    }
                    break;
                case "qjccc":  //请假出差查看
                    {
                        rr_url += "UI_QJCC_INFO.html?id=" + id + "&r=" + Math.random();
                    }
                    break;
                case "jfbxa":  //经费报销添加
                    {
                        rr_url += "UI_JFBX_BXMX.html?r=" + Math.random();
                    }
                    break;
                case "jfbxb":  //经费报销列表
                    {
                        rr_url += "UI_JFBX_LIST.html?r=" + Math.random();
                    }
                    break;
                case "jfbxc":  //经费报销查看
                    {
                        rr_url += "UI_JFBX_INFO.html?id=" + id + "&r=" + Math.random();
                    }
                    break;
                case "dbsxa":  //任务待办添加
                    {
                        rr_url += "UI_DBSX_INPUT.html?r=" + Math.random();
                    }
                    break;
                case "dbsxb":  //任务待办列表
                    {
                        rr_url += "UI_DBSX_LIST.html?r=" + Math.random();
                    }
                    break;
                case "dbsxc":  //任务待办列表(部门)
                    {
                        rr_url += "UI_DBSX_DPLIST.html?r=" + Math.random();
                    }
                    break;
                case "dbsxd":  //任务待办查看
                    {
                        rr_url += "UI_DBSX_INFO.html?id=" + id + "&r=" + Math.random();
                    }
                    break;
                case "xxzx":  //消息中心
                    {
                        rr_url += "UI_XXZX_LIST.html?r=" + Math.random();
                    }
                    break;
                case "lcspa":  //流程审批添加
                    {
                        rr_url += "UI_LCSP_LCLIST.html?r=" + Math.random();
                    }
                    break;
                case "lcspb":  //流程审批列表
                    {
                        rr_url += "UI_LCSP_LIST.html?r=" + Math.random();
                    }
                    break;
                case "lcspc":  //流程审批查看
                    {
                        rr_url += "UI_LCSP_INFO.html?id=" + id + "&r=" + Math.random();
                    }
                    break;
                case "dxgla":  //短信添加
                    {
                        rr_url += "UI_DXGL_INPUT.html?r=" + Math.random();
                    }
                    break;
                case "dxglb":  //短信列表
                    {
                        rr_url += "UI_DXGL_LIST.html?r=" + Math.random();
                    }
                    break;
                case "zxzxa":  //咨询添加
                    {
                        rr_url += "UI_ZXZX_INPUT.html?r=" + Math.random();
                    }
                    break;
                case "zxzxb":  //咨询列表
                    {
                        rr_url += "UI_ZXZX_XMLIST.html?r=" + Math.random();
                    }
                    break;
                case "zxzxc":  //咨询查看
                    {
                        rr_url += "UI_ZXZX_INFO.html?id=" + id + "&r=" + Math.random();
                    }
                    break;
                case "jhapa":  //计划安排添加
                    {
                        rr_url += "UI_JHAP_INPUT.html?r=" + Math.random();
                    }
                    break;
                case "jhapb":  //计划安排列表
                    {
                        rr_url += "UI_JHAP_LIST.html?r=" + Math.random();
                    }
                    break;
                case "jhapc": //计划安排查看
                    {
                        rr_url += "UI_JHAP_INFO.html?id=" + id + "&r=" + Math.random();
                    }
                    break;
                case "menu": //菜单列表
                    {
                        rr_url += "UI_BASE_PAGE.html?r=" + Math.random();
                    }
                    break;
            }
            return rr_url;

        }
        

    </script>
</head>
<body>
   
</body>
</html>
